<template>
  <div class="innerPageTable-box-OneTwo innerPageTable-out-flex">
     <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="modelForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item prop="name" :label="$t('module.tenantManage.msgModelName')">
          <Input
            type="text"
            :maxlength="30"
            v-model.trim="searchForm.name"
            placeholder
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="code" :label="$t('module.tenantManage.msgModelCode')">
          <Input
            type="text"
            :maxlength="30"
            v-model.trim="searchForm.code"
            placeholder
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="button" class="search-solt-btn">
           <RPButton optType="search" @click="search" />
           <RPButton optType="reset" @click="reset" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="messageModelTable" :config="modelTableConfig">
      <div slot="table-bar">
        <RPButton optType="create" @click="addModel" />
      </div>
    </InnerPageTable>
  </div>
</template>

<script>
import messageEdit from './messageEdit.vue'
import { messageModelColumns } from './columns.js'
import { mailTemplateList, mailTplDetails, deleteMailTpl } from '@api/flowable/tenantManage.js'
export default {
  name: 'mail-template',
  data() {
    return {
      searchForm: {
        name: '',
        code: ''
      },
      modelTableConfig: {
        loadDataFn: ({ responseProcess, param }) => {
          mailTemplateList(param).then(({ data }) => {
            console.log(data)
            data.currentPage = data.data.pageNum
            delete data.data.pageNum
            data.recordCount = data.data.total
            delete data.data.total

            data.recordList = data.data.list
            delete data.data.list
            responseProcess(data)
          })
        },
        columnsFn: messageModelColumns.bind(this),
        autoFirst: true,
        loading: false,
        initParam: { state: 1 }
      }
    }
  },
  methods: {
    search() {
      //刷新列表
      this.$refs['messageModelTable'].load(this.searchForm)
    },
    reset() {
      this.$refs['modelForm'].resetFields()
      this.search()
    },
    addModel() {
      let messageInfo = {}
      new this.$pageModal(
        messageEdit,
        {
          props: {
            messageInfo
          }
        },
        data => {
          if (data) {
            this.search()
          }
        }
      )
    },
    editMailTpl(row) {
      mailTplDetails(row.id).then(({ data }) => {
        let messageInfo = data
        new this.$pageModal(
          messageEdit,
          {
            props: {
              messageInfo
            }
          },
          data => {
            if (data) {
              this.search()
            }
          }
        )
      })
    },
    delMailTpl(row) {
      new $confirm(this.$t('common.warning.confirmToDelete'), this).then(() => {
        deleteMailTpl(row.id).then(response => {
          this.$Message.success({
            content: this.$t('common.deleteSuccess'),
            duration: 3
          })
          this.search()
        })
      })
    }
  }
}
</script>